package com.chuangke.system.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chuangke.common.db.page.CkPageQuery;
import com.chuangke.common.http.HttpResult;
import com.chuangke.system.entity.SysApiLog;
import com.chuangke.system.service.SysApiLogService;

import cn.hutool.core.util.StrUtil;

@RestController
@RequestMapping("apilog")
public class SysApiLogController {

	@Autowired
	private SysApiLogService sysApiLogService;

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/findpage")
	public HttpResult findPage(@RequestBody Map<String,Object> params) {
		String startDate = (String)params.get("startDate") ;
		String endDate = (String)params.get("endDate") ;
		CkPageQuery query = new CkPageQuery(params) ;
		QueryWrapper<SysApiLog> queryWrapper = new QueryWrapper<>() ;
		if(!StrUtil.isBlank(startDate) && !StrUtil.isBlank(endDate)) {
			queryWrapper.lambda().ge(SysApiLog::getCreatedAt, startDate).le(SysApiLog::getCreatedAt, endDate) ;
		}
		queryWrapper.lambda().orderByDesc(SysApiLog::getCreatedAt) ;
		return HttpResult.ok(sysApiLogService.page(query.getPage(),queryWrapper));
	}
	
}
